package com.gjt.zyglxt.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.gjt.zyglxt.dao.IMemberDao;
import com.gjt.zyglxt.dto.MemberDTO;
import com.gjt.zyglxt.model.Member;
import com.gjt.zyglxt.service.IMemberService;
import com.gjt.zyglxt.unti.POIUtil;

import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * MemberController
 */
@RestController
@RequestMapping("/member")
public class MemberController {

    @Resource
    private IMemberService memberService;
    @Resource
    private IMemberDao memberDao;
    
   
    @ApiOperation(value = "分页查询",notes = "分页查询")
    @PostMapping("/findPage")
    public Map<String,Object> findPage(@RequestBody MemberDTO dto){
       Map<String,Object> map = new HashMap<String,Object>();
       Page<Member> page = memberService.findPage(dto);
       map.put("code", 0);
       map.put("data", page.getContent());
       return map;
    }

    @ApiOperation(value = "保存会员信息",notes = "添加/修改会员信息")
    @PostMapping("/saveMember")
    public Member saveMember(@RequestBody Member m){
        return memberService.saveMember(m);
    }

    @ApiOperation(value = "删除会员信息",notes = "删除会员信息")
    @ApiImplicitParam(name = "id",value = "主键",required = true,paramType = "path")
    @DeleteMapping("/{id}")
    public void del(@PathVariable Integer id){
        memberService.del(id);
    }

    @ApiOperation(value = "批量添加",notes = "批量添加")
    @PostMapping("/path")
    public int addAll(){
        String path = "C:\\Users\\DELL\\Desktop\\会员登记表.xlsx";
        List<Member> list = new ArrayList<Member>(); 
        try {
           list = POIUtil.improtMember(path);
        } catch (Exception e) {
           e.printStackTrace();
        }
        return  memberService.addAll(list);
    }

    @ApiOperation(value = "批量删除",notes = "批量删除")
    @PostMapping("/delAll")
    public void delAll(@RequestBody  List<Member> id) {
   
        memberService.delAll(id);
        
    }
}